package com.laikan.reader.bookfriend.fragment;

import android.os.Bundle;
import android.view.View;

import com.laikan.library.httpvolley.helper.VolleyErrorHandler;
import com.laikan.library.httpvolley.response.HttpResponse;
import com.laikan.library.managers.ToastMgr;
import com.laikan.reader.bookfriend.adapter.BaseListAdapter;
import com.laikan.reader.bookfriend.entity.PageAutherBean;
import com.laikan.reader.bookfriend.requester.SimpleRequestListener;
import com.laikan.reader.bookfriend.utils.Constant;
import com.socks.library.KLog;

/**
 * Created by lingyt on 2016/11/15.
 * 个人页面Fragment
 */
public abstract class AutherFragment extends BaseListFragment {

    private String autherId;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (mBundle != null) {
            String userId = mBundle.getString(Constant.USER_ID,"");
            setAutherId(userId);
        }
    }

    @Override
    protected void setListener() {

    }

    @Override
    protected void onClickEvent(View view) {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected abstract BaseListAdapter getAdapter();

    @Override
    protected abstract void loadData(int pageNo);

    /*protected SimpleCallback<PageAutherBean> mCallback = new SimpleCallback<PageAutherBean>(this) {

        @Override
        public void onSuccess(HttpResponse httpResponse, PageAutherBean o) {
            setFragmentData(o);
        }

        @Override
        public void onError(VolleyErrorHandler errorHandler) {
            onRequestDataError();
        }

    };
*/

    protected SimpleRequestListener mCallback = new SimpleRequestListener(this){

        @Override
        public void onSuccess(HttpResponse httpResponse) {
            PageAutherBean pageAutherBean = mGson.fromJson(httpResponse.responseContent,PageAutherBean.class);
            setFragmentData(pageAutherBean);
        }

        @Override
        public void onError(VolleyErrorHandler errorHandler) {
            onRequestDataError();
        }
    };


    protected String getAuthorId() {
//      test  return "7418238";
        return autherId;
    }

    protected void setAutherId(String userId) {
        this.autherId = userId;
    }


    @Override
    protected void onRequestDataEmpty() {
        if (!isLoadOnce) {
            mTvEmptyTip.setText("暂无更多数据");
            mTvEmptyTip.setVisibility(View.VISIBLE);
            KLog.w(args,"服务器返回数据为空");
        } else {
            ToastMgr.showShortToast("服务器返回数据为空");
            KLog.w(args,"服务器返回数据为空");
        }
    }
}
